import _ from "lodash";
import { Component, Vue, Prop } from "vue-property-decorator";
//import { ipcRenderer } from "electron";
import { LOWDB_CONN, LOWDB_GET, LOWDB_SET } from '@/bglib/lowdb_easy';

import RootNode from "@/components/ObjectCom/RootNode.vue";

const CONN_KEY = "lowdb-test-01";
const FILE_KEY = "lowdb_t.json";

@Component({
    components: {
        RootNode
    }
})
export default class LowdbTest extends Vue {

    public low_data: Object = {
        "aaa": "test_a",
        "bbb": 123.54,
        "ccc": {
            "aaax": "文件夹、组织架构、生物分类、国家地区等等，世间万物的大多数结构都是树形结构。使用树控件可以完整展现其中的层级关系，并具有展开收起选择等交互功能。文件夹、组织架构、生物分类、国家地区等等，世间万物的大多数结构都是树形结构。使用树控件可以完整展现其中的层级关系，并具有展开收起选择等交互功能。",
            "bbbx": 123.54,
            x: {
                title: "对象中的对象"
            }
        },
        "ddd_arr": [
            "sigo", 125, 34e5,
            ["数组中的数组"],
            {
                title: "数组中的对象"
            }
        ]
    }; // 测试用数据

    public edit_value: any = null;

    async created() {

        let res = await this.$ipcR.send(LOWDB_CONN, {
            key: CONN_KEY,
            file: FILE_KEY
        });


        //let { db_key, message, status = "success" } = res;

    }

    async read(path: string) {
        let res = await this.$ipcR.send(LOWDB_GET, {
            key: CONN_KEY,
            path
        });
        _.set(this.low_data, path, res);
    }

    async save(path: string) {
        let res = await this.$ipcR.send(LOWDB_SET, {
            key: CONN_KEY,
            path,
            value: this.edit_value
        });
        _.set(this.low_data, path, this.edit_value);
    }

    async toObject(path: string) {
        let res = await this.$ipcR.send(LOWDB_SET, {
            key: CONN_KEY,
            path,
            value: {}
        });
        _.set(this.low_data, path, {});
    }

}